<?php

if (!defined('BASEPATH'))
	exit('No Direct Access Allowed !');

/**
*  
*/
class dashboard extends CI_Controller
{
	
	function __construct()
	{

		parent::__construct();
		 $this->load->model('m_login');
         $this->load->model('m_dashboard');

	}

	function index(){
		$cek = $this->session->userdata('logged_in');
		if (empty($cek)) {
			header('location:' . site_url('login'));
		} else {
            $d['t_dokter'] = $this->m_dashboard->total_dokter();
            $d['t_user'] = $this->m_dashboard->total_user();
            $d['t_hewan'] = $this->m_dashboard->total_hewan();
			$this->load->view('global/header');
			$this->load->view('dashboard/index', $d);
			$this->load->view('global/footer');
		}
	}

	function edit_profil(){
		$cek = $this->session->userdata('logged_in');
        if (empty($cek)) {
            header('location:' . site_url('admin'));
        } else {
            $dt = $this->m_login->edit();
            $d['nama'] = $dt->nama;
            $d['username'] = $dt->username;
            $d['pass'] = "";
            $d['email'] = $dt->email;
            $d['id'] = $dt->id_admin;
            $this->load->view('global/header');
            $this->load->view('dashboard/edit_profil', $d);
            $this->load->view('global/footer');
        }
	}

	function simpan_profil(){
		$cek = $this->session->userdata('logged_in');
        if (empty($cek)) {
            header('location:' . site_url());
        } else {
            $this->form_validation->set_rules('nama', 'Nama', 'trim|required');
            $this->form_validation->set_rules('username', 'Username', 'trim|required');
             $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]');
            $this->form_validation->set_rules('repassword', 'Konfirmasi Password', 'trim|required|min_length[6]');
            if ($this->input->post('submit')) {
                if ($this->form_validation->run() == FALSE) {
                    $d['nama'] = $this->input->post('nama');
                    $d['username'] = $this->input->post('username');
                    $d['email'] = $this->input->post('email');
                    $d['pass'] = $this->input->post('password');
                    $d['id'] = $this->input->post('id');
                    $this->load->view('global/header');
                    $this->load->view('dashboard/edit_profil', $d);
                    $this->load->view('global/footer');
                } else {
                    $a = $this->input->post('id');
                    $this->m_login->update($a);
                    $nm = $this->m_login->edit();
                    $n = $nm->nama;
                    $this->session->set_userdata('nama_pengguna', $n);
                   // $this->session->set_flashdata('result_pass', 'Password sudah berhasil diubah.');
                    header('location:' . site_url('dashboard/edit_profil'));
                }
            }
        }

	}


}